package com.wtwd.campus.send;

import com.wtwd.campus.common.Constants;
import com.wtwd.campus.entity.Command;
import com.wtwd.campus.entity.MqMessage;
import com.wtwd.campus.entity.MqVcomNotDisturb;

import java.util.Map;
import java.util.TreeMap;

/**
 * @Author: ldaoliang
 * @DateTime: 2022/1/7 9:33
 * @Description:
 */
public class VcomNotDisturbSender implements Sender{
    @Override
    public Command dealMessage(MqMessage mqMessage) {
        MqVcomNotDisturb mqVcomNotDisturb = (MqVcomNotDisturb) mqMessage.getObject();
        String imei = mqVcomNotDisturb.getImei();
        String commandNumber = mqVcomNotDisturb.getCommandNumber();
        TreeMap<Integer, String> notDisturbData = mqVcomNotDisturb.getNotDisturbData();
        StringBuilder sb = new StringBuilder("*WT,");
        sb.append(imei).append(",NOTDISTURB,").append(commandNumber).append(",");
        for(Map.Entry<Integer,String> entry : notDisturbData.entrySet()){
            int weekdays = entry.getKey();
            sb.append(weekdays).append(",");
            String timeData = entry.getValue();
            sb.append(timeData);
        }
        String commandContent = sb.substring(0,sb.length()-1) + "#";
        Command command=new Command();
        command.setImei(imei);
        command.setCommandNumber(commandNumber);
        command.setStatus(Constants.COMMAND_NEED_SAVE);
        command.setContent(commandContent);
        command.setCmd(Constants.VCOM_NOT_DISTURB);
        return command;
    }
}
